<template>
  <div class="HomePage">

    <div v-for="(item,index) in newData" :key="index">
      <Swiper v-if='item.type=="swiperList"' :dataList="item.data"></Swiper>
      <Icons v-if='item.type=="iconsList"' :dataList="item.data" @iconClick="iconClick"></Icons>
      <Recommend v-if='item.type=="recommendList"' :dataList="item.data"></Recommend>
    </div>

    <div style="height: 100px;"></div>

  </div>
</template>

<script>
import Swiper from "@/components/home/Swiper";
import Icons from "@/components/home/Icons";
import Recommend from "@/components/home/Recommend";
import {api1} from "@/common/api/request";

export default {
  name: "HomePage",
  data(){
    return {
      newData:[],
      path:'/home/HomePage'
    }
  },
  components:{
    Swiper,
    Icons,
    Recommend
  },

  // activated() { //路由活跃时，添加上离开时的路径
  //   this.$router.push(this.path)
  //   this.$store.state.selectedId = this.$store.state.activeUrl.indexOf(this.path)
  // },
  // beforeRouteLeave(to,from,next){ //离开路由组件前
  //   this.path = this.$route.path  //记录此时路由路径
  //   next()
  // },

  created() {
    this.apiInit()
  },
  methods:{
    apiInit(){
      api1({
        url: '/api/index_list/0/data/1'
      }).then(res => {
        this.newData = res.data
      })
    },
    iconClick(path){
      this.$router.replace(path)
      this.$store.state.selectedId = this.$store.state.activeUrl.indexOf(path)
    }
  }
}
</script>

<style scoped lang="scss">
.HomePage{
  position: relative;
  top: 92px;
  right: 0;
  left: 0;
}
</style>